package engine;

import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;


/**
 * CollisionDetector.java
 * 
 * Utility class used to determine which provided Sprites a certain Character
 * collides with
 * 
 * @author Connor Gordon, Niel Lebeck
 * 
 */
public class CollisionDetector {

    /**
     * Returns a list containing the Sprites a single Character collides with
     * 
     * @param c the specified Character object
     * @param spriteList list of all sprites, which are in fact "collidable"
     * @return list of sprites that collide with the Character c
     */
    public List<Sprite> doesCollide (Character c, Iterable<Sprite> spriteList) {
        List<Sprite> collisionList = new ArrayList<Sprite>();
        Rectangle characterBounds = c.getBounds();
        for (Sprite currentSprite : spriteList) {
            Rectangle spriteBounds = currentSprite.getBounds();
            if (characterBounds.intersects(spriteBounds) && !c.equals(currentSprite)) {
                collisionList.add(currentSprite);
            }
        }
        return collisionList;
    }
}
